<template>
  <div class="table-box">
    <div class="table-search">
      <el-form :inline="true" :model="form">
        <el-form-item label="用户UID">
            <el-input v-model="form.uid" placeholder="用户UID" />
          </el-form-item>
        <el-form-item label="订单状态">
          <el-select v-model="form.status" placeholder="订单状态">
            <el-option label="待支付" :value="0" />
            <el-option label="成功" :value="10" />
            <el-option label="退款" :value="20" />
            <el-option label="失败" :value="30" />
          </el-select>
        </el-form-item>
        <el-form-item label="订单号">
          <el-input v-model="form.order_no" placeholder="订单号" />
        </el-form-item>
        <el-form-item label="商品ID">
          <el-input v-model="form.goods_id" placeholder="商品id" />
        </el-form-item>
        <el-form-item label="时间">
          <el-date-picker
            v-model="form.timeData"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="截止日期"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="onQuery">查询</el-button>
          <el-button @click="onReset">重置</el-button>
          <el-button type="primary" plain @click="onExport">导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="card content-box">
      <div class="table">
        <el-table :data="tableData" border v-loading="loading">
          <el-table-column
            prop="uid"
            label="用户UID"
            align="center"
            width="180"
          />
          <el-table-column
            prop="order_no"
            label="订单号"
            align="center"
            width="230"
          />
          <el-table-column
            prop="goods_id"
            label="产品ID"
            align="center"
            width="200"
          />
          <el-table-column
            prop="pay_channel"
            label="支付渠道"
            align="center"
            width="150"
          />
          <el-table-column
            prop="package_name"
            label="包名/BundleID"
            align="center"
            width="180"
          />
          <el-table-column
            prop="original_order_id"
            label="原始订单ID"
            align="center"
            width="180"
          />

          <el-table-column
            prop="purchase_order_id"
            label="购买订单ID"
            align="center"
            width="180"
          />
          <el-table-column prop="purchase_token" label="购买token" align="center"  width="280"/>
          <el-table-column prop="receipt_data" label="订单信息" align="center"  width="300"/>
          <el-table-column prop="receipt_detail" label="订单详情" align="center"  width="300"/>
          <el-table-column
            prop="refund_time"
            label="退款时间"
            align="center"
            width="180"
          />
          <el-table-column
            prop="status"
            label="状态"
            align="center"
            width="180"
          />
          <el-table-column
            prop="subscription_status"
            label="订阅商品状态"
            align="center"
            width="180"
          />
          <el-table-column
            prop="product_type"
            label="商品类型"
            align="center"
            width="130"
          />
          <el-table-column
            prop="region_code"
            label="结算区域"
            align="center"
            width="180"
          />
          <el-table-column
            prop="createtime"
            label="通知时间"
            align="center"
            width="180"
            :formatter="formatterTime"
          />
          <el-table-column
            prop="updatetime"
            label="更新时间"
            align="center"
            width="180"
            :formatter="formatterTime"
          />
          
          
         
          
        </el-table>
        <div class="table-pagination">
          <el-pagination
            :current-page="pageable.pageNum"
            :page-size="pageable.pageSize"
            :page-sizes="[10, 25, 50, 100]"
            :background="true"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pageable.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, reactive } from "vue";

import { formatterTime, timestamp, exportToExcel } from "@/utils/utils";
import { payOrderNotifyListApi } from "@/api/slotsgame/order/order";

const tableData = ref([]);


const formData = {
  order_no: "",
  goods_id: "",
  status: "",
  uid:"",
  timeData: [],
};
const form = reactive({ ...formData });
const loading = ref(false);
const pageable = reactive({
  pageNum: 1,
  pageSize: 10,
  total: 0,
});

// 参数
const param = () => {
  return {
    page: pageable.pageNum,
    pagesize: pageable.pageSize,
    goods_id: form.goods_id,
    order_no: form.order_no,
    status: form.status,
    uid:form.uid,
    start: form.timeData[0] ? timestamp(form.timeData[0].valueOf()) : "",
    end: form.timeData[1] ? timestamp(form.timeData[1].valueOf()) : "",
  };
};
//格式化


// 获取表格数据
const getTbaleData = async () => {
  loading.value = true;

  try {
    const res = await payOrderNotifyListApi(param());
    loading.value = false;
    tableData.value = res.data.results;
    pageable.total = res.data.count;
  } catch (error) {
    loading.value = false;
  }
};
// 重置
const onReset = () => {
  Object.assign(form, formData);
};
// 查询
const onQuery = async () => {
  getTbaleData();
};
// 导出
const onExport = async () => {
  const data = Object.assign(param(), { export: 1 });
  const res = await payOrderNotifyListApi(data);

  let head = {
    id: "ID",
    uid: "用户UID",
    order_no: "订单号",
    goods_id: "产品ID",
    pay_channel: "支付渠道",
    package_name: "包名/BundleID",
    original_order_id: "原始订单ID",
    purchase_order_id: "购买订单ID",
    purchase_token: "购买token",
    receipt_data: "订单信息",
    receipt_detail: "订单详情",
    refund_time: "退款时间",
    status: "状态",
    subscription_status: "订阅商品状态",
    product_type: "商品类型",
    region_code: "结算区域",
    createtime: "通知时间",
    updatetime: "更新时间",
  };
  exportToExcel(res.data.results, head, "Slotsgame-订单支付通知");
};

// 条数
const handleSizeChange = (number) => {
  pageable.pageSize = number;
  getTbaleData();
};
// 页码
const handleCurrentChange = (number) => {
  pageable.pageNum = number;
  getTbaleData();
};
onMounted(() => {
  getTbaleData();
});
</script>
